from my_base_sk.MySK import *
from native_function import *

prompt = """
已知，数据库形式为
CREATE TABLE Courses (
    id INT AUTO_INCREMENT PRIMARY KEY,
    course_date DATE NOT NULL,
    start_time TIME NOT NULL,
    end_time TIME NOT NULL,
    course_name VARCHAR(255) NOT NULL,
    instructor VARCHAR(255) NOT NULL
);

用自然语言解释用户的SQL查询的意图和查询结果

用户输入：{{$input}}

查询结果：{{DBConnectorPlugin.query_database $input}}
"""

# 加载 native function
kernel.add_plugin(DBConnectorPlugin(cursor), "DBConnectorPlugin")

prompt_template_config = PromptTemplateConfig(
    template=prompt,
    description="查询数据库",
    execution_settings={service_id: req_settings},
    input_variables=[
        InputVariable(name="input", description="The user query", is_required=True),
    ],
)

db_query_function = kernel.add_function(
    function_name="db_query",
    plugin_name="MyDemoPlugin",
    prompt_template_config=prompt_template_config,
)

result = asyncio.run(
    run_function(
        db_query_function,
        KernelArguments(
            input="SELECT COUNT(*) as count FROM Courses WHERE instructor = '王卓然'"
        )
    )
)

print(result)
